<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */

defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'house';
$return=array();
$return['setting']=$this->plugin_setting('basic');
$uniacid=$_SESSION['uniacid'];
if($_RQ['op']=='main'){

	//查询我的房屋
	
	$households=pdo_getall('jy_smallquan_household',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$houses=array();
	if(!empty($households)){
		foreach($households as $household){
			$house=pdo_get('jy_smallquan_house',array('uniacid'=>$_SESSION['uniacid'],'id'=>$household['hid']));
			array_push($houses,$house);
		}
	}
	if($houses){
		foreach($houses as &$item){
			$item['building']=pdo_get('jy_smallquan_building',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['bid']));
		}
	}
	$household=pdo_get('jy_smallquan_household',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$return['houses']=$houses;
	$return['status']=1;
	$return['household']=$household;
	exi($return);
}
if($_RQ['op']=='house'){
	$id=$_RQ['id'];
	if(!$id){
		$household=pdo_get('jy_smallquan_household',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'status'=>1));
		if(empty($household)){
			exi('','','jy_smallquan/area/');
		}
		$house=pdo_get('jy_smallquan_house',array('uniacid'=>$_SESSION['uniacid'],'id'=>$household['hid']));
	}else{
		$house=pdo_get('jy_smallquan_house',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}
	$house['building']=pdo_get('jy_smallquan_building',array('id'=>$house['bid']));
	//业主
	$yezhu=pdo_get('jy_smallquan_household',array('uniacid'=>$_SESSION['uniacid'],'hid'=>$house['id'],'shenfen'=>1));
	//其他成员
	$members=pdo_getall('jy_smallquan_household',array('uniacid'=>$_SESSION['uniacid'],'hid'=>$house['id'],'status'=>1,'shenfen'=>0));
	if($members){
		foreach($member as &$members){
			$member['phone']=substr($member['mobile'],-4);	
		}
	}
	$yezhu['nickname']=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$yezhu['mid']),'nickname');	
	$yezhu['avatar']=pdo_getcolumn('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$yezhu['mid']),'avatar');	
	$yezhu['phone']=substr($yezhu['mobile'],-4);	
	$return['house']=$house;
	$return['members']=$members;
	$return['yezhu']=$yezhu;
	$return['status']=1;
	exi($return);
	
}
if($_RQ['op']=='list'){
	$households=pdo_getall('jy_smallquan_household',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$houses=array();
	if(!empty($households)){
		foreach($households as $household){
			$house=pdo_get('jy_smallquan_house',array('uniacid'=>$_SESSION['uniacid'],'id'=>$household['hid']));
			array_push($houses,$house);
		
		}
			if($houses){
				
				foreach($houses as &$item){
					$item['building']=pdo_get('jy_smallquan_building',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['bid']));
					//print_r($item['building']);exit;
				}
			}
	}	
	$return['houses']=$houses;
	$return['members']=$members;
	$return['yezhu']=$yezhu;
	$return['status']=2;
	exi($return);
}	
		


